﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Wicresoft.RDW.Presentation;
using Wicresoft.RDW.Model;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
using Wicresoft.RDW.Helper;

namespace Wicresoft.RDW.Ajax
{
    /// <summary>
    /// GetLabList 的摘要说明
    /// </summary>
    public class GetLabList : IHttpHandler
    {

        public bool IsReusable
        {
            get { return false; }
        }
        protected HttpRequest Request
        {
            get
            {
                return HttpContext.Current.Request;
            }
        }
        protected HttpResponse Response
        {
            get
            {
                return HttpContext.Current.Response;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int locationId = int.Parse(Request.Params["LocationId"]);
            IList<Lab> labs = new List<Lab>();
            labs = LabPresent.GetList(x => x.LocationId == locationId);
            List<object> items = new List<object>();
            foreach(var lab in labs)
            {
                items.Add(new { LabId = lab.LabId, Name = lab.Name });
            }
            Response.Write(JsonConvert.SerializeObject(items));
        }
    }
}